#include "ItemModel.h"

ItemModel::ItemModel(QObject *parent):
    QAbstractListModel(parent)
{
    m_testNumber=0;
}

int ItemModel::rowCount(const QModelIndex &parent) const
{
    return m_seamTaskList.size();
}

int ItemModel::columnCount(const QModelIndex &parent) const
{
    return 1;
}

QVariant ItemModel::data(const QModelIndex &index, int role) const
{
    SeamTask *fsasas=m_seamTaskList.at(index.row());
        if(fsasas==NULL)
        {
            return QVariant();
        }
        else
        {
            switch (role) {
            case Qt::UserRole:
                return fsasas->seamname;
            case Qt::DisplayRole:
                return fsasas->status;
            case Qt::SizeHintRole:
                return QSize(0, 100);
            default:
                return QVariant();
            }
        }
        return QVariant();
}

void ItemModel::add(QString name,WorkStatus sta)
{
    SeamTask *data=new SeamTask;
    data->status   =  sta;
    data->seamname =  name;
    m_seamTaskList.push_back(data);
    emit layoutChanged();
    m_testNumber++;
}

SeamTask *ItemModel::at(int index)
{
    return m_seamTaskList.at(index);
}

void ItemModel::sync()
{
    // emit dataChanged()
    emit layoutChanged();
}

